<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/7/15
 * Time: 23:51
 */

namespace common\models\Service;


use common\models\DAO\UserSign;
use common\msg\UserMsg;
use yii\base\Exception;

class SignService {
    public static function day($userID)
    {
        $result['status'] = 0;
        $result['msg'] = UserMsg::$time_out;
        $integral = 3;
        $transaction = \Yii::$app->db->beginTransaction();
        try {
            $userSign = new UserSign();
            $userSign->userID = $userID;
            $userSign->date = date('Ymd');
            $userSign->integral = $integral;
            $userSign->save();
            $userInfo['type'] = 6;
            $userInfo['integral'] = $integral;
            $userInfo['des'] = '每日签到';
            $userInfo['recID'] = $userID;
            $integral_result = IntegralService::addIntegral($userInfo); 
            if(!$integral_result){
                $transaction->rollBack();
                return $result;
            }else{
                $transaction->commit();
                return ['status'=>1];
            }
        } catch (Exception $e) {
            $transaction->rollBack();
            $result['msg'] = UserMsg::$alsign;
            return $result;
        }
    }
}